import Vue from 'vue'
import Vuex from 'vuex'
import VuexPersistence from 'vuex-persist'
import member from './modules/member';
import user from './modules/user';
Vue.use(Vuex)


// 创建 VuexPersistence 实例
const storage = {
  getItem: (key) => uni.getStorageSync(key),
  setItem: (key, value) => uni.setStorageSync(key, value),
  removeItem: (key) => uni.removeStorageSync(key)
}
const vuexPersist = new VuexPersistence({
	key: 'estateApp', // 存储的键名
	storage: storage, // 使用 localStorage
	reducer: (state) => ({
		 // count:state.count
		 member:state.member  ,//持久化member模块的所有状态,
		 user:{
			 count:state.user.count   //持久化 user模块count状态
		 }
		 
	}) // 选择需要持久化的状态 如果缓存所有的变量,可以去掉reducer
});
 
 export default new Vuex.Store({
	 
	// state: {
	// 	count: 0,
	// },
	// getters: {
	// 	doubleCount(state) {
	// 		return state.count * 2;
	// 	}
	// },
	// mutations: {
	// 	update(state, payload) {
	// 		state.count += payload;
	// 	}
	// },
	// actions: {
	// 	updateSync(context, payload) {
	// 		setTimeout(() => {
	// 			context.commit("update", payload)
	// 		}, 2000)
	// 	}
	// },
	 modules:{
		member,user
	 },
	 plugins:[vuexPersist.plugin]
	 
	 
 })

